package com.hr.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.hr.dao.WageDao;
import com.hr.model.WageModel;
@Repository
public class WageDaoImpl implements WageDao{
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Override
	public List<WageModel> findAll() {
		String sql = "select * from wage ";
		List<WageModel> wageList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<WageModel>(WageModel.class));
		return wageList;
	}
	@Override
	public boolean addWage(WageModel wageModel) {
		String sql = "insert into wage (wage_base,wage_overtime,wage_check,wage_absent,wage_safety," +
				"wage_jxjj,wage_final,wage_date,user_id) values(?,?,?,?,?,?,?,?,?)";
		Object[] params = new Object[]{
				wageModel.getWage_base(),
				wageModel.getWage_overtime(),
				wageModel.getWage_check(),
				wageModel.getWage_absent(),
				wageModel.getWage_safety(),
				wageModel.getWage_jxjj(),
				wageModel.getWage_final(),
				wageModel.getWage_date(),
				wageModel.getUser_id()
		};
		jdbcTemplate.update(sql, params);
		return true;
	}
	@Override
	public boolean checkWageHaveSend(String user_id, String wage_date) {
		String sql = "select count(*) from wage where user_id=? and wage_date=?";
		int result = jdbcTemplate.queryForInt(sql, user_id,wage_date);
		if(result==0)
			return false;
		else
			return true;
	}
	@Override
	public List<WageModel> findByUserId(String user_id) {
		String sql = "select * from wage where user_id=?";
		List<WageModel> wageList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<WageModel>(WageModel.class),user_id);
		return wageList;
	}
	@Override
	public boolean deleteWage(String user_id, String wage_date) {
		String sql = "delete from wage where user_id=? and wage_date=?";
		jdbcTemplate.update(sql, user_id,wage_date);
		return true;
	}

}
